package com.wd.lookcar.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.wd.buycar.view.activity.NewCarDetailsActivity
import com.wd.common.bean.QuickSearchBean
import com.wd.lookcar.R

/**
 * Created by Android Studio.
 * author: 张文龙
 * Date:
 * Time: 2023/9/13 20:30
 * 备注：
 */
class LookCarAdapter(
    private var context: Context,
    private var list: ArrayList<QuickSearchBean.Result>,
) : RecyclerView.Adapter<LookCarAdapter.Holder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        val view = LayoutInflater.from(context).inflate(R.layout.look_car_item, parent, false)
        return Holder(view)
    }

    override fun getItemCount() = list.size

    override fun onBindViewHolder(holder: Holder, position: Int) {
        when (position) {
            0 -> {
                Glide.with(context)
                    .load(R.mipmap.look_content_label1)
                    .into(holder.imgPosition)
            }

            1 -> {
                Glide.with(context)
                    .load(R.mipmap.look_content_label2)
                    .into(holder.imgPosition)
            }

            2 -> {
                Glide.with(context)
                    .load(R.mipmap.look_content_label3)
                    .into(holder.imgPosition)
            }

            else -> {
                holder.imgPosition.visibility = View.INVISIBLE
            }
        }
        holder.carName.text = list[position].name
        Glide.with(context)
            .load(list[position].bgImageUrl)
            .into(holder.imgCarHic)
        holder.carPrice.text = list[position].lowBid.toString() + "-" + list[position].highBid.toString()
        holder.itemView.setOnClickListener{
            var intent = Intent(context,NewCarDetailsActivity::class.java)
            intent.putExtra("name",list[position].name)
            var a= list[position].categoryId
            intent.putExtra("id",a)
            context.startActivity(intent)
        }
    }

    class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var imgPosition: ImageView
        var imgCarHic: ImageView
        var carName: TextView
        var carPrice: TextView

        init {
            imgCarHic = itemView.findViewById(R.id.car_img)
            imgPosition = itemView.findViewById(R.id.car_position)
            carName = itemView.findViewById(R.id.car_name)
            carPrice = itemView.findViewById(R.id.car_price)
        }
    }
}